package Dao;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public interface Dao {
    public  default Connection getConnection() {
        DataSource dataSource = null;
        Connection connection = null;
        try {
            Context context=new InitialContext();
            dataSource=(DataSource)context.lookup("java:/comp/env/jdbc/community");
            try {
                connection=dataSource.getConnection();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }
        return connection;
    }
}
